import path from "path";
import { defineConfig, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
// https://vitejs.dev/config/
// const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
export default defineConfig((env) => {
  const viteEnv = loadEnv(env.mode, process.cwd());

  return {
    plugins: [uni()],
    css: {
      loaderOptions: {
        // 给 less-loader 传递 Less.js 相关选项
        less: {},
      },
    },
    lintOnSave: false,
    base: viteEnv.VITE_PUBLIC_PATH,
    // plugins: setupPlugins(viteEnv),
    server: {
      host: "0.0.0.0",
      port: 1002,
      open: false,
      proxy: {
        "/api": {
          rewrite: (path) => path.replace("/api/", "/api/"),

          target: "viteEnv.VITE_APP_API_BASE_URL",
          changeOrigin: true, // 允许跨域
        },
      },
    },
  };
});
